package board;

import ibatis.Account;
import ibatis.AccountDAOIbatis;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.List;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class BoardDAOIbatis {

	public static void main(String[] args){
		new BoardDAOIbatis();
	}
/**
* SqlMapClient instances are thread safe, so you only need one.
* In this case, we'll use a static singleton.  So sue me.  ;-)
*/
private static SqlMapClient sqlMapper;

/**
* It's not a good idea to put code that can fail in a class initializer,
* but for sake of argument, here's how you configure an SQL Map.
*/
static {
	try {
	  Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
	  sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
	  System.out.println(sqlMapper);
	  reader.close(); 
	} catch (IOException e) {
	  // Fail fast.
	  throw new RuntimeException("Something bad happened while building the SqlMapClient instance." + e, e);
	}
	}
	
	public static List selectAllBoards () throws SQLException {
	return sqlMapper.queryForList("selectAllBoards");
	}
	
	public static Board selectBoardByNum  (int num) throws SQLException {
	return (Board) sqlMapper.queryForObject("selectBoardByNum", num);
	}
	
	public static void insertBoard (Board board) throws SQLException {
	sqlMapper.insert("insertBoard", board);
	}
	
	public static void deleteboardByNum (int num) throws SQLException {
		sqlMapper.delete("deleteboardByNum", num);
		}

	public static void updateBoard(Board board) throws SQLException {
		// TODO Auto-generated method stub
		sqlMapper.update("updateBoard", board);
		
	}

}
	
